package com.jnr.hb.user;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;

import com.jnr.hb.R;

import cn.bmob.v3.BmobUser;
import cn.bmob.v3.exception.BmobException;
import cn.bmob.v3.listener.SaveListener;

public class RegisterActivity extends AppCompatActivity {

    private EditText mRegisterName;
    private EditText mRegisterPasswerd;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_register);
        initView();
    }

    private void initView() {
        mRegisterName = (EditText) findViewById(R.id.registerName);
        mRegisterPasswerd = (EditText) findViewById(R.id.registerPasswerd);
    }
    //注册
    public void registerStart(View view){
        String name = mRegisterName.getText().toString().trim();
        String passwerd = mRegisterPasswerd.getText().toString().trim();
        BmobUser bu = new BmobUser();
        if (name.equals("")||passwerd.equals("")){
            Toast.makeText(this, "用户名获密码为空", Toast.LENGTH_SHORT).show();
        }else {
            bu.setUsername(name);
            bu.setPassword(passwerd);
            bu.signUp(new SaveListener<Person>() {
                @Override
                public void done(Person s, BmobException e) {
                    if(e==null){
                        Toast.makeText(RegisterActivity.this, "注册成功", Toast.LENGTH_SHORT).show();
                        startActivity(new Intent(RegisterActivity.this,UserActivity.class));
                    }else{
                        Toast.makeText(RegisterActivity.this, "失败", Toast.LENGTH_SHORT).show();
                    }
                }
            });
        }
    }
}
